<?php

define('DOCUMENT_ROOT', dirname(dirname(__FILE__)));

$associative_values = parse_ini_string(file_get_contents(dirname(DOCUMENT_ROOT) . '/application/application.ini'), true);
// Get webservice URL from application
DEFINE('WEBSERVICE_URL', $associative_values['application']['http_webroot'].'/webservice/?');
DEFINE('BASE_ROOT', str_replace('/public', '', $associative_values['application']['http_webroot']));

DEFINE('GATEWAY_URL', 'inc/gateway.php'); 


function webservice_get($fields = array()) {
    $ch = curl_init(WEBSERVICE_URL);
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, WEBSERVICE_URL);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
    // Set POST data
    $fields_string = '';
    $fields_string = http_build_query($fields);
    rtrim($fields_string, '&');
    curl_setopt($ch, CURLOPT_POST, count($fields));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}